<script setup lang="ts">
import { reactive, ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import { useI18n } from "vue-i18n";
const { t } = useI18n();
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        code: "",
        name: "",
        layer: null,
        row: null,
        sort: null,
        warehouseid: null,
        note: "",
        status: 0
    }),
    wareList: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);
const wareList = ref(props.wareList);
const { switchStyle } = usePublicHooks();

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="80px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="20">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.encoding')" prop="code">
                    <el-input v-model="newFormInline.code" clearable :placeholder="t('racks.inputEncoding')" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.name')" prop="name">
                    <el-input v-model="newFormInline.name" clearable :placeholder="t('racks.inputName')" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.totalNumberOfFloors')" prop="layer">
                    <el-input-number v-model="newFormInline.layer" :disabled="newFormInline.status === 1"
                        controls-position="right" :placeholder="t('racks.enterTheTotalNumberOfLayers')" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.totalNumberOfColumns')" prop="row">
                    <el-input-number v-model="newFormInline.row" :disabled="newFormInline.status === 1"
                        controls-position="right" :placeholder="t('racks.enterTheTotalNumberOfColumns')" />
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="状态" prop="status">
          <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0"
            active-text="已生成货位" inactive-text="未生成货位" :style="switchStyle" />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.repository')" prop="warehouseid">
                    <el-select v-model="newFormInline.warehouseid" :placeholder="t('racks.selectWarehouse')"
                        style="width:100%">
                        <el-option v-for="item in wareList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racks.sort')" prop="sort">
                    <el-input-number v-model="newFormInline.sort" controls-position="right"
                        :placeholder="t('racks.inputSorting')" />
                </el-form-item>
            </re-col>
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('racks.remarks')" prop="note">
                    <el-input v-model="newFormInline.note" clearable :placeholder="t('racks.enterRemarks')"
                        type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
